{include file="public/head"/}
<style>
    body {
        background-color: #ffffff;
    }
</style>

<body>
    <div class="layui-form layuimini-form">
        <div class="layui-form-item">
            <label class="layui-form-label">授予权限</label>
            <div class="layui-input-inline" id="tree"></div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
                <a href="javascript:;"  class="layui-btn layui-btn-primary layui-border" lay-active="closePage">关闭</a>
            </div>
        </div>
    </div>
    </div>
    <script>
        layui.use(['form','tree','util'], function () {
            var form = layui.form,
                layer = layui.layer,
                util = layui.util,
                tree = layui.tree,
                $ = layui.$;

            tree.render({
                id: 'tree',
                elem: '#tree',  //绑定元素
                showCheckbox: true,
                data: {$data}
                });
            tree.setChecked('tree', {$checked});

            //监听提交
            form.on('submit(saveBtn)', function (data) {
                // 提交到方法 默认为本身
                loading =layer.load(1, {shade: [0.1,'#fff']});
                var rules = tree.getChecked('tree');

                $.post("{:url('setaccess')}",{'rules':rules,'group_id':{$id}},function(res){
                    layer.close(loading);
                    if(res.code > 0){
                      layer.msg(res.msg,{time:1800,icon:1});
                      // 关闭弹出层
                      setTimeout(() => {
                        var iframeIndex = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(iframeIndex);
                      }, 1800);
                    
                    }else{
                        layer.msg(res.msg,{time:1800,icon:2});
                    }
                });
            });
            
            util.event('lay-active',{
                closePage: function() {
                    var iframeIndex = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(iframeIndex);
                }
            });
        });
    </script>
    {include file="public/footer"/}